/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : course.js                                 
*  Description  : 코스공략 글보기 
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-04-27  김효순    Created.  
*  2012-04-30  김효순    Complete.  
*******************************************************************************/

jQuery(function($){
	// 상단 타이틀
	function clsCourseTitle()
	{
		this._HTMLDom = null;
		
		this._init();
	}
	
	clsCourseTitle.prototype = {
		_init: function(){
			var $layer = $("div#container>section#main_content>div.golf_board article.depth2_tab");
			
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.data("idx", null); // 인덱스로 관리
			
			this.display();
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, setIdx: function(val){
			var $layer = this.$getLayer();
			
			if(val == $layer.data("idx")) return false;
			
			$layer.data("idx", val);
			
			this.display();
			return true;
		}
		, display: function(){
			var $layer = this.$getLayer();
			var idx = $layer.data("idx");
			
			// 현재 인덱싱된 타이틀만 on설정
			$layer.find("li img").each(function(n){
				var imgSrc = $(this).attr("src");
				var szImgName = imgSrc.replace(/(.*)\/(.*).gif/g, function(){
					return arguments[1] + "/" + arguments[2].replace("_on", "");
				});
				
				$(this).attr("src", szImgName + ((idx == n) ? "_on":"") + ".gif");
			});
		}
	}
	
	// 코스정보
	function clsCourseInfo()
	{
		this._HTMLDom = null;
		this.infoData = null;
		
		this._init();
	}
	
	clsCourseInfo.prototype = {
		_init: function(){
			var $layer = $("article.board_view");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			var $tmp = $layer.find("img[alt='나이스샷']").parent("th").children().clone(true);
			$layer.find("img[alt='나이스샷']").parent("th").empty().append($tmp);
			$layer.find("img[alt='나이스샷']").after("<a href='#' />");
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, setInfo: function(thisData){
			this.infoData = thisData;
			this.display();
		}
		, getInfo: function(){
			return this.infoData;
		}
		, setWriterInfo: function(thisData){
			this.infoData["작성자"] = thisData;
			this.displayWriter();
		}
		, setNiceShotList: function(thisData){
			this.infoData["나이스샷"] = thisData;
			this.displayNiceShot();
		}
		, display: function(){
			var $layer = this.$getLayer();
			var thisClass = this;
			
			$layer.find("dl.view_tit dt:eq(0)").contents().filter(function(){
				return this.nodeType == 3;
			}).remove().end().end().prepend(this.infoData["제목"]);
			$layer.find("dl.view_tit dt:eq(0) span").html("(" + this.infoData["댓글수"] + ")");
			$layer.find("dl.view_tit dd:eq(0) span:eq(0) img").attr("src", _gf.getDefaultProfileImage());
			$layer.find("dl.view_tit dd:eq(0) span:eq(1)").html(this.infoData["작성자"]["닉네임"]);
			
			$layer.find("thead th.gol").html(this.infoData["골프장명"] + this.infoData["코스명"] + "<span class='ff_normal'>" + this.infoData["홀명"].trim() + "H</span>");
			$layer.find("thead th:eq(1)>span").html(this.infoData["작성일"] + "<span>" + this.infoData["작성시"] + "</span>");

			$layer.find("thead th:eq(2) span:eq(1)").html(this.infoData["조회수"]);
			
			$layer.find("thead th:eq(3) a:first").html("나이스샷(0)");
			
			$layer.find("tbody td:eq(0) div").html(this.infoData["내용"]);
			
			// 이미지 리사이징
			document.objUtil.executeThread(function(){
				return $layer.find("table tbody td img").length;
			}, function(){
				$layer.find("table tbody td img").load( function(){
					if($(this).width() > 650) $(this).width(650);
				});
			});
		}
		, displayWriter: function(){
			var $layer = this.$getLayer();
			var d = this.infoData["작성자"];
			
			$layer.find("dl.view_tit dd:eq(0) span:eq(0) img").attr("src", _gf.filePath2Url(d["이미지"])).error(function(){
				$(this).attr("src", _gf.getDefaultProfileImage());
			});
			
			$layer.find("dl.view_tit dd:eq(0) span:eq(1)").html(d["닉네임"]).hover(function(){
				_gf.showProfileLayer($(this), d, "right", -255, $(this).height());
			}, function(){
				_gf.closeProfileLayer();
			});
		}
		, displayNiceShot: function(){
			var $layer = this.$getLayer();
			var thisClass = this;
			var d = this.infoData["나이스샷"];
			
			$layer.find("thead th:eq(3) a:first").html("나이스샷(" + d.length+ ")").unbind("hover").hover(function(){
				if(d.length) _gf.showMemberLayer($(this), d, "right", -115, $(this).height());
			}, function(){
				_gf.closeMemberLayer();
			});
		}
		, spinStart: function(){
			var $layer = this.$getLayer();
			
			$layer.find("dl, table").hide();
			if($layer.find("div#tmpSpin").length == 0){
				$layer.find("table").after("<div id='tmpSpin' style='position:relative; width:700px; height:100px;'></div>");
			}
			$layer.find("div#tmpSpin").show().spin();
		}
		, spinEnd: function(){
			var $layer = this.$getLayer();
			
			$layer.find("div#tmpSpin").spin(false).hide();
			$layer.find("dl, table").show();
		}
	}
	
	// 코스댓글
	function clsCourseCommentList()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsCourseCommentList.prototype = {
		_init: function(){
			$layer = $("article.board_view div.reply_area");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("dl:first").clone(true)
			}
			
			this.setList([]);
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, setList: function(thisData){
			this.listData = thisData;
			this.display();
		}
		, setWriterInfo: function(commentKey, thisData){
			for(var i=0;i<this.listData.length;i++){
				if(this.listData[i]["키"]+"" == commentKey) break;
			}
			
			if(i<this.listData.length){
				this.listData[i]["작성자"] = thisData;
				this.displayWriter(i);
			}
		}
		, setNiceShotList: function(commentKey, thisData){
			for(var i=0;i<this.listData.length;i++){
				if(this.listData[i]["키"]+"" == commentKey) break;
			}
			
			if(i<this.listData.length){
				this.listData[i]["나이스샷"] = thisData;
				this.displayNiceShot(i);
			}
		}
		, display: function(){
			var $layer = this.$getLayer();
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.find("p.reply_num span").html("(" + this.listData.length + ")");
			
			$layer.find("dl").remove();
			for(var i=0;i<this.listData.length;i++){
				$layer.find("div.reply_regist").before($element.clone(true));
			}
			$layer.find("dl").each(function(n){
				$(this).find("dt:first img").attr("src", _gf.getDefaultProfileImage());
				$(this).find("dd:first p.nickname a").html(thisClass.listData[n]["작성자"]["닉네임"]);
				$(this).find("dd:first p.reply_date").contents().filter(function(){
					return this.nodeType == 3;
				}).remove().end().end().prepend(thisClass.listData[n]["작성일"]);
				$(this).find("dd:first p.reply_date span").html(thisClass.listData[n]["작성시"]);
				$(this).find("dd:first div:first").html(thisClass.listData[n]["내용"]);
				if(thisClass.listData[n]["내꺼"] != "Y"){
					$(this).find("dd:first p.reply_del").hide();
				}
				$(this).find("p.reply_nice span").css("cursor", "pointer").html("나이스샷(0)");
			});
		}
		, displayNiceShot: function(n){
			var $layer = this.$getLayer();
			var thisClass = this;
			var $obj = $layer.find("dl").eq(n);
			var d = this.listData[n]["나이스샷"];
			
			$obj.find("p.reply_nice span").html("나이스샷(" + d.length + ")").hover(function(){
				if(d.length) _gf.showMemberLayer($(this), d, "right", -115, $(this).height());
			}, function(){
				_gf.closeMemberLayer();
			});
		}
		, displayWriter: function(n){
			var $layer = this.$getLayer();
			var thisClass = this;
			var $obj = $layer.find("dl").eq(n);
			
			$obj.find("dt:first img").attr("src", this.listData[n]["작성자"]["이미지"]).error(function(){
				$(this).attr("src", _gf.getDefaultProfileImage());
			});
			$obj.find("dd:first p.nickname a").html(this.listData[n]["작성자"]["닉네임"]).hover(function(){
				_gf.showProfileLayer($(this), thisClass.listData[n]["작성자"], "left", 0, $(this).height());
			}, function(){
				_gf.closeProfileLayer();
			});;
		}
		, spinStart: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("dl").hide();
			if($layer.find("div#tmpSpin").length == 0){
				$layer.find("p:first").after("<div id='tmpSpin' style='position:relative; width:700px; height:100px;'></div>");
			}
			$layer.find("div#tmpSpin").show().spin();
		}
		, spinEnd: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("div#tmpSpin").spin(false).hide();
			$layer.find("dl").show();
		}
		, getKey: function(n){
			return this.listData[n]["키"]
		}
	}
	
	// 댓글등록
	function clsCommentRegist()
	{
		this._HTMLDom = null;
		
		this._init();
	}
	
	clsCommentRegist.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content div.reply_area div.reply_regist");
			this._HTMLDom = {
				"$layer": $layer
			}
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, reset: function(){
			this.$getLayer().find("textarea").val("");
		}
		, focus: function(){
			this._HTMLDom["$layer"].find("textarea").trigger("focus");
		}
		, getValue: function(){
			return this._HTMLDom["$layer"].find("textarea").val();
		}
		, spinStart: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.children().hide();
			if($layer.find("div#tmpSpin").length == 0){
				$layer.prepend("<div id='tmpSpin' style='position:relative; width:580px; height:100px;' />");
			}
			$layer.find("div#tmpSpin").show().spin();
		}
		, spinEnd: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.children().show();
			$layer.find("div#tmpSpin").hide().spin(false);
		}
	}
	
	function clsComm()
	{
		this.courseData = null;
		this.courseCommentList = null;
		
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){
			this.courseData = {
				"제목": null
				, "작성자": {
					"아이디": null
					, "이미지": null
					, "닉네임": null
				}
				, "골프장명": null
				, "코스명": null
				, "홀명": null
				, "작성일": null
				, "작성시": null
				, "조회수": null
				, "내용": null
				, "댓글수": null
			}
			
			this.courseCommentList = [
				{
					"키": null
					, "작성자": {
						"아이디": null
						, "이미지": null
						, "닉네임": null
					}
					, "내용": null
					, "작성일": null
					, "작성시": null
					, "내꺼": null
				}
			]
		}
		, getCourseInfo: function(q_seq){
			var thisClass = this;
			
			//ajax
			var serviceName = "getDetailKnowhowBoard";
			var options = {
				"board_seq": q_seq
				, "modpage_yn": "N"
			}
			document.objGlobal.ajax({
				"sid": "KB001",
				"servicename": "getDetailKnowhowBoard"
			}, options, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": _gf.getResultMsg(ret)
					, "결과값": {}
				}
				
				var items = ret["msp"]["contents"]["items"];
				if(items){
					var obj = items;
					var reg_date = _util.nvl(obj["reg__date"])+""
					var reg_time = _util.nvl(obj["reg__time"])+""
					
					var golfName = "";
					var courseName = "";
					var hole = "";
					
					switch(_util.nvl(obj["userWriteYn"])){
						case "Y":
							golfName = _util.nvl(obj["golfclub__data"]);
							courseName = _util.nvl(obj["course__data"]);
							hole = _util.nvl(obj["hole__data"]);
							break;
						case "N":
							golfName = _util.nvl(obj["golfclub__name"]);
							courseName = _util.nvl(obj["course__info__name"]);
							hole = _util.nvl(obj["hole__no"]);
							break;
					}
					
					res["결과값"] = {
						"제목": _util.nvl(obj["title"])
						, "작성자": {
							"아이디": _util.nvl(obj["reg__id"])
							, "이미지": _gf.filePath2Url(_util.nvl(obj["user__image"]))
							, "닉네임": _util.nvl(obj["reg__nickname"])
						}
						, "골프장명": golfName
						, "코스명": courseName
						, "홀명": hole+""
						, "작성일": reg_date.substr(0,4) + "-" + reg_date.substr(4, 2) + "-" + reg_date.substr(6,2)
						, "작성시": reg_time.substr(0,2) + ":" + reg_time.substr(2, 2)
						, "조회수": _util.nvl(obj["hit"], 0)
						, "내용": _util.nvl(obj["content"])
						, "댓글수": _util.nvl(obj["cr__cnt"], 0)
					}
				}
				
				document.objControl.finishCourseInfo(res);
			});
		}
		, getCourseData: function(){
			return this.courseData;
		}
		, getCourseCommentList: function(q_seq){
			var thisClass = this;
			
			//ajax
			var serviceName = "getKnowhowCommentList";
			var options = {
				"board_seq": q_seq
			}
			document.objGlobal.ajax({
				"sid": "KB001",
				"servicename": serviceName,
				"listcount": 100,
				"currpageno": 1
			}, options, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": _gf.getResultMsg(ret)
					, "결과값": []
				}
				
				var items = ret["msp"]["contents"]["items"];
				if(items){
					if(!items.length) items = new Array(items);
					for(var i=0;i<items.length;i++){
						var obj = items[i];
						var reg_date = _util.nvl(obj["reg__date"])+"";
						var reg_time = _util.nvl(obj["reg__time"])+"";
						
						res["결과값"].push({
							"키": _util.nvl(obj["reply__seq"])
							, "작성자": {
								"아이디": _util.nvl(obj["reg__id"])
								, "이미지": _gf.filePath2Url(_util.nvl(obj["user__image"]))
								, "닉네임": _util.nvl(obj["reg__nickname"])
							}
							, "내용": _util.enter2br(_util.nvl(obj["content"]))
							, "작성일": reg_date.substr(0,4) + "." + reg_date.substr(4, 2) + "." + reg_date.substr(6,2)
							, "작성시": reg_time.substr(0,2) + ":" + reg_time.substr(2, 2)
							, "내꺼": _util.nvl(obj["my__article__yn"])
						});
					}
				}
				
				document.objControl.finishCourseCommentList(res);
			});
		}
		, getCourseCommentData: function(){
			return this.courseCommentList;
		}
		, courseCommentSubmit: function(arg){
			var thisClass = this;
			
//			arg = {
//				"게시판키": null
//				, "내용": null
//			}

			// ajax
			document.objGlobal.ajax({
				"sid": "KB001",
				"servicename": "regKnowhowComment"
			}, {
				"content": encodeURIComponent(arg["내용"])
				, "board_seq": arg["게시판키"]
			}, function(ret){
				document.objControl.finishCourseCommentSubmit({
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": document.objGlobal.getResultMsg(ret)
				});
				
				document.objControl.finishCourseCommentSubmit(ret);
			});
		}
		, courseCommentDelete: function(arg){
			var thisClass = this;
			
//			arg = {
//				"부킹키": null
//				, "댓글키": null
//			}
			
			// ajax
			document.objGlobal.ajax({
				"sid": "BB001",
				"servicename": "deleteBookingComment"
			}, {
				"board_seq": arg["부킹키"]
				, "reply_seq": arg["댓글키"]
			}, function(ret){
				document.objControl.finishBookingCommentDelete({
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": document.objGlobal.getResultMsg(ret)
				});
				
				document.objControl.finishBookingCommentSubmit(ret);
			});
		}
		// 나이스샷 리스트
		, getNiceShotList: function(arg){
			var thisClass = this;
			
			//ajax
			var serviceName = "getKnowhowBoardNiceshot";
			var options = {
				"board_seq": arg["코스공략코드"]
			}
			
			if(arg["댓글코드"]) options["reply_seq"] = arg["댓글코드"]
			_gf.ajax({
				"sid": "KB001"
				, "servicename": serviceName
				, "listcount": 10000
				, "currpageno": 1
			}, options, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": _gf.getResultMsg(ret)
					, "결과값": []
				}
				
				if(arg["댓글코드"]) res["댓글코드"] = arg["댓글코드"];
				
				var items = ret["msp"]["contents"]["items"];
				if(items){
					if(!items.length) items = new Array(items);
					for(var i=0;i<items.length;i++){
						var obj = items[i];
						
						res["결과값"].push({
							"아이디": _util.nvl(obj["reg__id"])
							, "닉네임": _util.nvl(obj["reg__nickname"])
							, "이미지": _util.nvl(obj["user__image"])
						});
					}
				}
				
				document.objControl.finishNiceShotList(res);
			});
		}
		// 나이스샷
		, niceShotSubmit: function(arg){
			var thisClass = this;
			
			//ajax
			var serviceName = "updateNiceshot";
			var options = {
				"board_seq": arg["코스공략코드"]
			}
			
			if(arg["댓글코드"]) options["reply_seq"] = arg["댓글코드"]
			_gf.ajax({
				"sid": "KB001"
				, "servicename": serviceName
			}, options, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": _gf.getResultMsg(ret)
				}
				
				if(arg["댓글코드"]) res["댓글코드"] = arg["댓글코드"];
				
				document.objControl.finishNiceShotSubmit(res);
			});
		}
		// 삭제
		, courseDelete: function(arg){
			var thisClass = this;
			
			//ajax
			var serviceName = "deleteKnowhowBoard";
			var options = {
				"board_seq": arg["코스공략코드"]
			}
			_gf.ajax({
				"sid": "KB001"
				, "servicename": serviceName
			}, options, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": _gf.getResultMsg(ret)
				}
				
				document.objControl.finishCourseDelete(res);
			});
		}
	}
	
	
	// 컨트롤
	function clsControl()
	{
		this.objComm = null;
		this.objCourseTitle = null;
		this.objCourseInfo = null;
		this.objCourseCommentList = null;
		this.objCommentRegist = null;
		
		this.ynMy = _util.getParam("q_my");
		this.courseKey = _util.getParam("q_seq");
		
		this._permitStart = null;
		
		this._init();
	}
	
	clsControl.prototype = {
		_init: function(){
			this._preload();
			
			this.objComm = new clsComm();
			this.objCourseTitle = new clsCourseTitle();
			this.objCourseInfo = new clsCourseInfo();
			this.objCourseCommentList = new clsCourseCommentList();
			this.objCommentRegist = new clsCommentRegist();
			
			this._beforeStart();
			this._bind();
		}
		, _preload: function(){
			_gf.spinStart();
		}
		, _beforeStart: function(){
			var thisClass = this;
			this._permitStart = {
				
			}
			
			_util.executeThread(function(){
				for(var k in thisClass._permitStart){
					if(!thisClass._permitStart[k]) return false;
				}
				
				return true;
			}, function(){
				_gf.spinEnd();
				thisClass._start();
			});
		}
		, _bind: function(){
			var thisClass = this;
			
			// 전체게시글, 내가쓴글
			this.objCourseTitle.$getLayer().on("click", "li", function(){
				var n = thisClass.objCourseTitle.$getLayer().find("li").index($(this));
				document.location.href = "course.html" + ((n) ? "?q_my=Y":"");
			});
			
			$("div#container section#main_content").on("click", "img[alt='수정'], img[alt='삭제'], img[alt='목록'], img[alt='글쓰기']", function(){
				var alt = $(this).attr("alt");
				
				switch(alt){
					case "수정":
						thisClass.goWritePage(thisClass.courseKey);
						break;
					case "삭제":
						if(!confirm("게시물을 삭제 하시겠습니까?")) return;
				
						thisClass.objComm.courseDelete({
							"코스공략코드": thisClass.courseKey
						});
						break;
					case "목록":
						thisClass.goListPage();
						break;
					case "글쓰기":
						thisClass.goWritePage();
						break;
				}
			});
			
			// 나이스샷
			this.objCourseInfo.$getLayer().on("click", "thead th:eq(3) a:first", function(){
				if(!_util.getCookie("member_id")){
					if(!confirm(_LOGIN_TEXT)) return;
					_gf.goLogin();
					return;
				}
				
				thisClass.objComm.niceShotSubmit({
					"코스공략코드": thisClass.courseKey
				});
			});
			
			// 댓글 나이스샷
			this.objCourseCommentList.$getLayer().on("click", "p.reply_nice span", function(){
				if(!_util.getCookie("member_id")){
					if(!confirm(_LOGIN_TEXT)) return;
					_gf.goLogin();
					return;
				}
				
				var n = thisClass.objCourseCommentList.$getLayer().find("p.reply_nice span").index($(this));
				var k = thisClass.objCourseCommentList.getKey(n);
				
				thisClass.objComm.niceShotSubmit({
					"코스공략코드": thisClass.courseKey
					, "댓글코드": k
				});
			});
			
			this.objCommentRegist.$getLayer().on("focus", "textarea", function(){
				if(!_util.getCookie("member_id")){
					if(!confirm(_LOGIN_TEXT)){
						$(this).trigger("blur");
						return;
					}
					_gf.goLogin();
					return;
				}
			});
			
			// 댓글등록
			this.objCommentRegist.$getLayer().on("click", "img[alt='댓글등록']", function(){
				if(!_util.getCookie("member_id")){
					if(!confirm(_LOGIN_TEXT)) return;
					_gf.goLogin();
					return;
				}
				
				if(!_gf.validComment(thisClass.objCommentRegist.getValue())){
					alert(thisClass.objCommentRegist.getError());
					thisClass.objCommentRegist.focus();
					return;
				}
				
				thisClass.objCommentRegist.spinStart();
				
				thisClass.objComm.courseCommentSubmit({
					"게시판키": thisClass.courseKey
					, "내용": thisClass.objCommentRegist.getValue()
				});
			});
			
			// 페이스북 공유
			$("div#container section#main_content").on("click", "a:contains('페이스북 공유하기')", function(){
				var info = thisClass.objCourseInfo.getInfo();
				
				var b = "";
				
				var $b = thisClass.objCourseInfo.$getLayer().find("div.view_detail img").each(function(){
					b += "<img src='" + $(this).attr("src") + "' />";
				});
				
				var t = info["제목"];
				var d = thisClass.objCourseInfo.$getLayer().find("div.view_detail").text();
				var r = document.location.href;
				
				_util.facebook_sharer(t, d, b, r);
			});
		}
		, _start: function(){
			// 전체게시글로 default 설정
			this.objCourseTitle.setIdx((this.ynMy == "Y") ? 1:0);
			
			// 코스정보
			this.objCourseInfo.spinStart();
			this.objComm.getCourseInfo(this.courseKey);
			
			// 댓글
			this.objCourseCommentList.spinStart();
			this.objComm.getCourseCommentList(this.courseKey);
		}
		// 코스정보 완료
		, finishCourseInfo: function(ret){
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			var thisClass = this;
			
			this.objCourseInfo.spinEnd();
			this.objCourseInfo.setInfo(ret["결과값"]);
			
			_gf.getMemberInfo({
				"아이디": ret["결과값"]["작성자"]["아이디"]
				, "콜백": function(res, info){
					thisClass.objCourseInfo.setWriterInfo(info);
				}
			});
			
			this.objComm.getNiceShotList({
				"코스공략코드": this.courseKey
			});
		}
		// 댓글 완료
		, finishCourseCommentList: function(ret){
			var thisClass = this;
			
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			this.objCourseCommentList.spinEnd();
			this.objCourseCommentList.setList(ret["결과값"]);
			
			for(var i=0;i<ret["결과값"].length;i++){
				_gf.getMemberInfo({
					"아이디": ret["결과값"][i]["작성자"]["아이디"]
					, "댓글코드": ret["결과값"][i]["키"]
					, "콜백": function(res, info, arg){
						thisClass.objCourseCommentList.setWriterInfo(arg["댓글코드"], info);
					}
					
				});
				
				this.objComm.getNiceShotList({
					"코스공략코드": this.courseKey
					, "댓글코드": ret["결과값"][i]["키"]
				});
			}
		}
		// 댓글 작성 완료
		, finishCourseCommentSubmit: function(ret){
			this.objCommentRegist.spinEnd();
			
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			this.objCommentRegist.reset();
			
			// 댓글
			this.objCourseCommentList.spinStart();
			this.objComm.getCourseCommentList(this.courseKey);
		}
		// 나이스샷 리스트 완료
		, finishNiceShotList: function(ret){
			if(ret["댓글코드"]){
				this.objCourseCommentList.setNiceShotList(ret["댓글코드"], ret["결과값"]);
			}else{
				this.objCourseInfo.setNiceShotList(ret["결과값"]);
			}
		}
		// 나이스샷 완료
		, finishNiceShotSubmit: function(ret){
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			if(ret["댓글코드"]){
				this.objComm.getNiceShotList({
					"코스공략코드": this.courseKey
					, "댓글코드": ret["댓글코드"]
				});
			}else{
				this.objComm.getNiceShotList({
					"코스공략코드": this.courseKey
				});
			}
		}
		// 삭제 완료
		, finishCourseDelete: function(ret){
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			this.goListPage();
		}
		// 리스트 이동
		, goListPage: function(){
			document.location.href = _ROOT + "/course/course.html" + _util.paramStringFilter(["q_seq"])
		}
		// 글쓰기 이동
		, goWritePage: function(q_seq){
			var szLink = _ROOT + "/course/course_write.html";
			
			if(q_seq){
				szLink += _util.paramStringFilter()
			}else{
				szLink += _util.paramStringFilter(["q_seq"])
			}
			
			document.location.href = szLink;
		}
	}
	
	document.objControl = new clsControl();
});